/* RISC-V Startup Code */

.section .text
.global _start

_start:
    /* Initialize stack pointer */
    la sp, _stack_end
    
    /* Clear BSS section */
    la t0, _bss_start
    la t1, _bss_end
    bgeu t0, t1, clear_done
clear_loop:
    sw zero, 0(t0)
    addi t0, t0, 4
    bltu t0, t1, clear_loop
clear_done:
    
    /* Call main function */
    jal ra, main
    
    /* Exit */
    li a0, 0
    li a7, 93  /* exit syscall */
    ecall

/* Infinite loop if main returns */
hang:
    j hang
